﻿#region License
/* ---------------------------------------------------------------- *
 *
 * This file is part of the Xcoordination Application Space
 * ("XcoAppSpace") http://www.xcoordination.com
 *
 * Copyright (C) 2009 Xcoordination http://www.xcoordination.com
 *
 * XcoAppSpace is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General
 * Public License as published by the Free Software Foundation.
 *
 * XcoAppSpace is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/
 * or write to the Free Software Foundation, Inc., 51 Franklin
 * Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * ---------------------------------------------------------------- */
#endregion

using System;
using XcoAppSpaces.Contracts.Service;

namespace XcoAppSpaces.Contracts.Transport
{
	/// <summary>
	/// Delegate definition for event that is raised by a transport service when a message is received.
	/// </summary>
	/// <param name="msg">The received message.</param>
	/// <param name="remoteAddress">The address from which the message was received.</param>
	/// <param name="commService">The transport service that received the message.</param>
	public delegate void MessageReceivedDelegate(XcoMessage msg, string remoteAddress, IXcoTransportService commService);
	
	/// <summary>
	/// Interface definition for Services that can be used for communication between application spaces.
	/// </summary>
	public interface IXcoTransportService : IXcoStatefulService, IDisposable
	{
		/// <summary>
		/// Event that is raised when a message is received.
		/// </summary>
		event MessageReceivedDelegate OnMessageReceived;

		/// <summary>
		/// The address of the server.
		/// </summary>
		string LocalAddress { get; }

		/// <summary>
		/// Sends a message to a remote space.
		/// </summary>
		/// <param name="msg">The messages that should be sent.</param>
		/// <param name="remoteAddress">The address of the space where the message should be sent.</param>
		void Send(XcoMessage msg, string remoteAddress);
	}
}
